/**
 * Chrowety
 * bg/request.js
 */

var Request = function(url, met, type, ctype)
{
    this.url = url;
    this.met = met;
    this.type = type ? type : "json";
    this.dados = {};
    this.sucesso = null;
    this.erro = null;
    this.contentType = ctype ? ctype : "application/x-www-form-urlencoded",

    this.init = function(opts)
    {
    	opts = opts || {};
    	
    	if( !opts.noOAuth )
    	{
        	var noToken = opts ? opts.noToken || false : false;
        	var _opts_ = {'noToken': noToken, 'token': null};
            this.url = OAuth.Sign(this.url, this.dados, this.met, _opts_).signed_url;
            this.dados = {};    		
    	}

        $.ajax({
            url: this.url,
            type: this.met,
            data: this.dados,
            dataType: this.type,
            contentType: this.contentType,
            success: this.sucesso,
            error: this.erro,
            timeout: utils.time.s(cfg.get('requestTimeout'))
        });
    };
};